/*
 * StrahlentherapiePSDoseDep3D.hh
 *
 *  Created on: Nov 27, 2010
 *      Author: holger
 */

#ifndef StrahlentherapiePSDoseDep3D_h
#define StrahlentherapiePSDoseDep3D_h 1

#include "StrahlentherapieVPrimitiveScorer3D.hh"

class StrahlentherapiePSDoseDep3D : public StrahlentherapieVPrimitiveScorer3D
{
	public:
		StrahlentherapiePSDoseDep3D(G4String name, G4int ni=1, G4int nj=1, G4int nk=1, G4int depi=0, G4int depj=1, G4int depk=2);
		virtual ~StrahlentherapiePSDoseDep3D() {}
		
	protected:
		G4bool ProcessHits(G4Step* aStep, G4TouchableHistory* ROhist);		

	private:
		G4double grayFactor;
		G4int n;
};

StrahlentherapiePSDoseDep3D::StrahlentherapiePSDoseDep3D(G4String name, G4int ni, G4int nj, G4int nk, G4int depi, G4int depj, G4int depk) : StrahlentherapieVPrimitiveScorer3D(name, ni, nj, nk, depi, depj, depk), grayFactor((kg/g)/(mm3/cm3)), n(0)
{}

G4bool StrahlentherapiePSDoseDep3D::ProcessHits(G4Step* aStep, G4TouchableHistory* ROhist)
{
	G4double edep = aStep->GetTotalEnergyDeposit();
	if ( edep == 0. ) return false;
	// Muttervolumenbox der Unterteilungen, funktioniert nur bei 3D-Unterteilung
	G4VSolid* solid = ROhist->GetSolid(3);
	G4double volume = solid->GetCubicVolume() / (fNi*fNj*fNk);
	G4double density = aStep->GetTrack()->GetMaterial()->GetDensity();
	// Faktor grayFactor notwendig, weil density in (e_SI*)g/cm3 aber volume in mm3, Gray = J/kg
	G4double dose    = edep / ( density * volume ) * grayFactor;
	
	//  s. StrahlentherapiePSEnergyDep3D.hh
//	dose *= aStep->GetPreStepPoint()->GetWeight(); // (Particle Weight)
	G4int index = GetIndex(ROhist);

	EvtMap->add(index, dose);
	return true;
}

#endif
